/**
 *
 * Created with IntelliJ IDEA.
 * @author  ranhongmin--2018/4/6
 * Description:
 */

var offset = 1;
$(function () {

    createList("");

    $(document).on("click","article",function () {
        var id = $(this).attr("data-wordId");
        window.location.href = "../../content.html?wordId="+id;
        // alert("click"+id);
    })



    $("#search_btn").click(function () {
        var see = $("#search_input").val();
        createList(see);
    })

});


function createList(search) {


    $.ajax({
        type: "POST",
        url: "../../wordMainAction/getWordList.json",
        dataType: "json",

        data: {
            "search":search,
            "offset": offset,
            "limit": 5
        },
        success: function (data) {
            createOneInfo(data);
        },
        error: function () {

        }
    });

}

function createOneInfo(data) {
    var ll = data.data.list;



    $('#word_div').empty();
    if(ll.length!=0) {
    $.each(data.data.list, function (i, n) {
            $('#word_div').append(" <article data-wordId=\""+n.id+"\"  class=\"blog-main\">" +
                "<h3 class=\"am-article-title blog-title\">" +
                " <a href=\"#\">" + n.wordName + "</a>" +
                "</h3>" +
                "<div class=\"am-g blog-content\">" +
                " <div class=\"am-u-lg-7\">" + n.wordIntroduction + "</div>" +
                "<div class=\"am-u-lg-5\">" +
                "<p><img src=\"" + n.wordImg + "\"></p>" +
                " </div>" +
                "</div></article>" +
                "        <hr class=\"am-article-divider blog-hr\">");
            // $("#word_div").append()
        });
    }else {
        $('#word_div').append(" <article class=\"blog-main\">" +
            "<h3 class=\"am-article-title blog-title\">" +
            " <a href=\"#\">没有。。。</a>" +
            "</h3>");
    }
}

function nextPage() {
    offset = Number(offset) + 1;
    createList("");

}

function previousPage() {
    if(offset!=1&&offset!=0){
        offset = Number(offset) - 1;
        createList("");
    }else {
        document.body.scrollTop=0;
        document.documentElement.scrollTop=0;
    }
}